<template>
  <div class="boxs-item">
    <div class="boxs-top" ref="animationRef1">
      <div class="boxs-top-title">
        <div>
          <titles :title="props.info.text" />
        </div>
      </div>
      <div class="subTitle" v-if="props.info.subTitle">——{{ props.info.subTitle }}</div>
      <textMax v-if="props.info.remarks" :data="props.info.remarks" :maxLen="109" />
    </div>
    <div ref="animationRef2" style="height: 464px; margin-bottom: 80px" @mouseup="endDrag" @mousedown="flag = false">
      <div class="boxs-content" ref="elScroll" :id="'boxs-content-scroll' + props.info.id">
        <div
          class="content-item"
          @click="pathChild(props.info, index)"
          v-for="(item, index) in props.info.children"
          :key="index"
          @mouseenter="imgEnter(index, props.info.children)"
          @mouseleave="imgLeave(index, props.info.children)"
          style="cursor: pointer"
        >
          <div class="img_box">
            <img
              draggable="true"
              v-if="item.value"
              :src="
                item.value
                  ? urls + item.value + '?imageView2/1/w/400/h/240/format/webp'
                  : 'http://101.34.143.36:8890/api/image/387939155165253/w_400,h_240'
              "
              alt=""
            />
            <UnitImageNull v-else></UnitImageNull>
            <div class="shadow"></div>
          </div>
          <div class="titleText">
            <span
              :class="'titleText' + props.info.children[index].id"
              class="title"
              :style="{
                fontSize: '20px',

                color: store.styleInfo.fontColor,
              }"
              >{{ item.text }}</span
            >
          </div>
          <div class="line" :class="'line' + props.info.children[index].id"></div>
          <div class="subTitle unit-subTitle" v-if="item.subTitle">——{{ item.subTitle }}</div>
          <span
            class="left-title1"
            :style="{
              fontSize: store.styleInfo.contentSize,

              color: '#666',
            }"
            >{{ item.remarks }}</span
          >
        </div>
      </div>

      <Scrollbar :dom="props.info.id" :flag="flag"> </Scrollbar>
    </div>
  </div>
</template>

<script setup lang="ts">
// @ts-nocheck
import { pathList, pathListLoop } from '../route';
import { urls } from '@/utils/request/upload';
import titles from '@/components/title/title.vue';
import buttonIcon from '@/components/title/buttonIcon.vue';
import textMax from './component/textMax2.vue';
import { ref, onMounted } from 'vue';
import { handlemouse } from '@/utils/minxin';
import { useProjectStore } from '@/store';
import { useRouter, useRoute } from 'vue-router';
import exhibitsScroll from '@/components/exhibitsScroll/exhibitsScroll';
import { imgEnter, imgLeave } from './component/hover';
import Scrollbar from './component/hwScrollX.vue';
import UnitImageNull from '@/components/unitImageNull/unitImageNull.vue';
import { FlagIcon } from 'tdesign-icons-vue-next';
const router = useRouter();
const route = useRoute();
const elScroll = ref(null);
const store = useProjectStore();
const props = defineProps({
  info: {
    type: Object,
  },
});

const animationRef1 = ref(null);
const animationRef2 = ref(null);
const pathChild = (e: any, index) => {
  store.setchildModel(e);
  store.setCurrent(index);

  router.push({
    name: route.meta.loopType ? pathListLoop[8] : pathList[8],
    query: { current: index, childId: props.info.id },
  });
};
onMounted(() => {
  // handlemouse('boxs-content-scroll');
  // exhibitsScroll(elScroll.value, `boxs-content-scroll${props.dom}`);

  animation1();
  // animation2();
});
const flag = ref(false);
const endDrag = () => {
  flag.value = true;
  console.log('flag.value', flag.value);
};
const animation1 = () => {
  const observer = new IntersectionObserver((entries) => {
    let canTrigger = true; // 标记是否可以触发
    entries.forEach((entry) => {
      if (entry.isIntersecting && canTrigger) {
        // 当元素进入视窗口时触发的代码
        animationRef1.value.classList.add('animation-box7');
        // 设置一个延迟时间，防止频繁触发
        canTrigger = false;
        setTimeout(() => {
          canTrigger = true;
        }, 500); // 设置延迟时间为 500 毫秒
      } else {
        // if (animationRef1.value) {
        //   animationRef1.value.classList.remove('animation-box7');
        // }
      }
    });
  });
  observer.observe(animationRef1.value);
};
const animation2 = () => {
  const observer = new IntersectionObserver((entries) => {
    let canTrigger = true; // 标记是否可以触发
    entries.forEach((entry) => {
      if (entry.isIntersecting && canTrigger) {
        // 当元素进入视窗口时触发的代码
        console.log('‘进入');

        elScroll.value.classList.add('animation-box6');
        // 设置一个延迟时间，防止频繁触发
        canTrigger = false;
        setTimeout(() => {
          canTrigger = true;
        }, 500); // 设置延迟时间为 500 毫秒
      } else {
        console.log('离开');
        // if (elScroll.value) {
        //   elScroll.value.classList.remove('animation-box6');
        // }
      }
    });
  });
  observer.observe(elScroll.value);
};
</script>

<style lang="less" scoped>
@import './index.less';

.boxs-item {
  // display: flex;
  width: 100%;
  min-height: 640px;
  overflow: hidden;
}
.boxs-top {
  display: flex;
  flex-direction: column;
  // align-items: center;
  justify-content: center;
  // padding-right: 120px;
  width: 900px;
  min-height: 142px;
  margin: auto;
  margin-bottom: 80px;
  opacity: 1;
}

.tdesign-demo-block--swiper {
  width: 100%;
}
.swiper-item {
  width: 580px;
  height: 100%;
  img {
    width: 100%;
    height: 100%;
  }
}
.boxs-content {
  display: flex;
  // flex: 1;
  overflow-y: hidden;
  // overflow-x: scroll;

  cursor: pointer;
}
.boxs-content::-webkit-scrollbar {
  height: 0 !important;
}
.content-item {
  width: 400px;
  // height: 240px;
  display: flex;
  flex-direction: column;
  margin-right: 20px;
  position: relative;
  justify-content: left;

  img {
    width: 400px;
    height: 240px;
  }
  .title {
    width: 100%;
    text-align: left;
    padding: 0;
  }
  .titleText {
    margin-top: 24px;
    text-align: left;
  }
  .left-title1 {
    line-height: 32px;
    display: block;
    height: 76px;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-line-clamp: 2; /* 控制最大行数 */
    padding-top: 15px;
  }
}
.content-item:last-child {
  margin-right: 0;
}
.boxs-top-title {
  display: flex;
  justify-content: center;
  width: auto;
  max-width: 100%;
}
.img_box {
  width: 400px;
  height: 240px;
  overflow: hidden;
  img {
    object-fit: cover;
  }
}
.content-item img {
  transition: all 0.5s;
}
.shadow {
  width: 100%;
  height: 240px;
  position: absolute;
  top: 0;
  background: rgba(0, 0, 0, 0);
  transition: all 0.5s;
  z-index: 99;
}
.content-item:hover .shadow {
  background: rgba(0, 0, 0, 0.4);
}
.content-item:hover img {
  transform: scale(1.1);
}
.line {
  width: 0px;
  height: 2px;
  background: #000;
  transform: all 0.5s;
}
.title {
  font-family: SourceHanSerifCN-Bold !important;
  font-weight: normal !important;
  line-height: 30px;
}
img {
  -webkit-user-drag: auto;
  -khtml-user-drag: auto;
  -moz-user-drag: auto;
  -o-user-drag: auto;
  user-drag: auto;
  user-select: auto;
}
.subTitle {
  text-align: center;
}
.unit-subTitle {
  text-align: left;
}
</style>
